/**
 * Copyright 2010-present Facebook.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.twodstar.photobattle;

import com.actionbarsherlock.app.SherlockFragment;
import com.facebook.Request;
import com.facebook.Response;
import com.facebook.Session;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import com.twodstar.photobattle.R;

public class Fragment_About extends SherlockFragment 
{
	private static Fragment_About m_Inst = null;
	
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
    {
        View view = inflater.inflate(R.layout.about , container, false);
        
        Button btn_View_Profile = (Button) view.findViewById(R.id.btnViewProfile);
        btn_View_Profile.setOnClickListener(new View.OnClickListener() 
		{
			@Override
			public void onClick(View v) 
			{
				OnButtonViewProfile();
			}
		});
        
        Button btn_View_ShareButton = (Button) view.findViewById(R.id.btnShareWall);
        btn_View_ShareButton.setOnClickListener(new View.OnClickListener() 
		{
			@Override
			public void onClick(View v) 
			{
				OnButtonShareWall();
			}
		});
        
        Button btn_View_2DStarGames = (Button) view.findViewById(R.id.btn2DStarGames);
        btn_View_2DStarGames.setOnClickListener(new View.OnClickListener() 
		{
			@Override
			public void onClick(View v) 
			{
				OnButton2DStarGames();
			}
		});
        
        return view;
    }
    
    public static Fragment_About Instance()
    {
    	if(m_Inst == null)
    	{
    		m_Inst = new Fragment_About();
    	}
    	return m_Inst;
    }
    
    
    private void OnButtonViewProfile()
    {
    	String url = "fb://profile/205318309520128";
 		Intent i = new Intent(Intent.ACTION_VIEW);
 		i.setData(Uri.parse(url));
 		
 		if(getActivity() != null)
 		{
 			getActivity().startActivity(i);
 		}
    }
    
    private void OnButtonShareWall()
    {
    	PostOnWall("https://play.google.com/store/apps/details?id=com.twodstar.aliencrusher_hd");
    }
    
    private void OnButton2DStarGames()
    {
    	Uri uri = Uri.parse("https://play.google.com/store/apps/developer?id=2DStar+Entertainment");	
	    Intent externalLink = new Intent(Intent.ACTION_VIEW, uri);	    
	    
	    try 
	    {
    		if(getActivity() != null)
    			getActivity().startActivity(externalLink);
        	
	    } 
    	catch (ActivityNotFoundException e) 
    	{
    		Log.i("game", "Error Redirecting to external Link");
    	}
    }
    
    
    private static void PostOnWall(String message) 
    {            	
    	if(Session.getActiveSession() ==  null)
    		return;
    	
    	if(Session.getActiveSession().isClosed())
    		return;
    	
        Request request = Request
                .newStatusUpdateRequest(Session.getActiveSession(), message, null, null, new Request.Callback() 
                {
                    @Override
                    public void onCompleted(Response response) 
                    {
                        
                    }
                });
        request.executeAsync();
    }
   
   
    
    
}
